import {_decorator, Component, Node, Label, find} from 'cc';

const {ccclass, property} = _decorator;

@ccclass('Message')
export class Message extends Component {

    private static _instance: Message = null;

    @property(Label)
    content: Label = null;


    public static get Instance() {
        // 只能通过自身进行初始化
        if (this._instance == null) {
            this._instance = find("Canvas/Message").getComponent(Message);
        }
        return this._instance;
    }

    start() {

    }

    update(deltaTime: number) {

    }

    public show(content: string, dealy: number = 3) {
        this.node.active = true;
        this.content.string = content;
        this.scheduleOnce(() => {
            this.close();
        }, dealy);
    }

    private close() {
        this.node.active = false;
    }
}


